package cn.com.xf.web;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import cn.com.xf.web.form.BaseForm;

public class XFMappingJacksonJsonView extends MappingJacksonJsonView {
	@Override
	protected Object filterModel(Map<String, Object> model) {
		Map<String, Object> result = new HashMap<String, Object>(model.size());
		Set<String> renderedAttributes = !CollectionUtils.isEmpty(super.getRenderedAttributes()) ? super
				.getRenderedAttributes() : model.keySet();
		for (Map.Entry<String, Object> entry : model.entrySet()) {
			if (!(entry.getValue() instanceof BindingResult) && renderedAttributes.contains(entry.getKey())) {
				if (!(entry.getValue() instanceof BaseForm)) {
					result.put(entry.getKey(), entry.getValue());
				}
			}
		}
		return result;
	}
}